package com.keyinong.caizhengting.tools;

import android.content.Context;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;

public class HttpTools {
    Context context;
    AsyncHttpClient client = new AsyncHttpClient();

    public HttpTools(Context context) {
        super();
        this.context = context;
    }

    /**
     * 登录请求
     */
    public void login(String phone, String password,
                      JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("phone", phone);
        params.put("password", password);
        client.post(context, Url.loginUrl, params, backcall);
    }

    /**
     * 获取验证码
     */
    public void yanzhengma(String phone, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("phone", phone);
        client.post(context, Url.yanzhengmaUrl, params, backcall);
    }

    /**
     * 注册
     */
    public void zhuce(String code, String phone, String password, String name, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("code", code);
        params.put("phone", phone);
        params.put("password", password);
        params.put("name", name);
        client.post(context, Url.zhuce, params, backcall);
    }

    /**
     * 获取忘记密码验证码
     */
    public void forgetpwdyanzhengma(String phone, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("phone", phone);
        client.post(context, Url.forgetpwdyanzhengmaUrl, params, backcall);
    }

    /**
     * 忘记密码
     */
    public void xiugaimima(String code, String phone, String password, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("code", code);
        params.put("phone", phone);
        params.put("password", password);
        client.post(context, Url.xiugaimimaUrl, params, backcall);
    }

    /**
     * 推荐商品
     */
    public void Tuijianshangpin(String token, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        client.post(context, Url.tuijianshangpinUrl, params, backcall);
    }

    /**
     * 所有商品
     */
    public void Allproducts(String token, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        client.post(context, Url.allProductsUrl, params, backcall);
    }

    /**
     * 商品二级分类
     */
    public void goodtwosort(String token, String catid, String page, String offset,
                            JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("catid", catid);
        params.put("page", page);
        params.put("offset", offset);
        client.post(context, Url.goodtwosort, params, backcall);
    }

    /**
     * 增加商品到购物车
     */
    public void addgoodscat(String token, String productid, String amount,
                            JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("productid", productid);
        params.put("amount", amount);
        client.post(context, Url.addgoodscat, params, backcall);
    }

    /**
     * 获得购物车信息
     */
    public void getShoppingCat(String token, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        client.post(context, Url.getShoppingCat, params, backcall);
    }

    public void getShoppingCarts(String token, JsonHttpResponseHandler handler) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        client.post(context, Url.getShoppingCat, params, handler);
    }

    /**
     * 更新购物车
     */
    public void refreshShoppingCat(String token, String id, String amount, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("id", id);
        params.put("amount", amount);
        client.post(context, Url.refreshShoppingCat, params, backcall);
    }

    /**
     * 移除商品信息
     */
    public void deletegoods(String token, String id, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("id", id);
        client.post(context, Url.deletegoods, params, backcall);
    }

    /**
     * 移除商品信息
     */
    public void remove(String token, String productid, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("productid", productid);
        client.post(context, Url.remove, params, backcall);
    }

    /**
     * 清空购物车信息
     */
    public void cleanShoppingCat(String token, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        client.post(context, Url.cleanShoppingCat, params, backcall);
    }

    /**
     * 确认订单
     */
    @Deprecated
    public void caidan(String token, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        client.post(context, Url.confirmCaidan, params, backcall);
    }

    public void confirmFood(String token, JsonHttpResponseHandler handler) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        client.post(context, Url.confirmFood, params, handler);
    }

    public void confirmGoods(String token, JsonHttpResponseHandler handler) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        client.post(context, Url.confirmGoods, params, handler);
    }

    /**
     * 保存订单
     */
//	public void saveorder(String token,String book,JsonHttpResponseHandler backcall){
//		RequestParams params = new RequestParams();
//		params.put("token", token);
//		params.put("book", book);
//		client.post(context, Url.saveOrder,params,backcall);
//	}
    @Deprecated
    public void newSaveOrder(String token, String book, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("book", book);
        client.post(context, Url.newSaveOrder, params, backcall);
    }

    public void saveFoodOrder(String token, String book, JsonHttpResponseHandler handler) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("book", book);
        client.post(context, Url.saveFoodOrder, params, handler);
    }

    public void saveGoodsOrder(String token, JsonHttpResponseHandler handler) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        client.post(context, Url.saveGoodsOrder, params, handler);
    }

    public void submitGoods(String token, int orderId, JsonHttpResponseHandler handler) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("orderid", orderId);
        client.post(context, Url.submitGoods, params, handler);
    }

    /**
     * 返回用户订单
     */
    public void myorder(String token, String page, String offset, int type, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("page", page);
        params.put("offset", offset);
        params.put("type", type);
        client.post(context, Url.myOrder, params, backcall);
    }

    /**
     * 返回订单详情
     */
    public void orderdetail(String token, String orderid, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("orderid", orderid);
        client.post(context, Url.orderDetail, params, backcall);
    }

    /**
     * 取消订单
     */
    public void cancelorder(String token, String orderid, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("orderid", orderid);
        client.post(context, Url.cancelOrder, params, backcall);
    }

    /**
     * 删除订单
     */
    public void deleteorder(String token, String orderid, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("orderid", orderid);
        client.post(context, Url.deleteOrder, params, backcall);
    }

    /**
     * 个人资料
     */
    public void person(String token, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        client.post(context, Url.Person, params, backcall);
    }

    /**
     * 添加收藏
     */
    public void addcollect(String token, String productid, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("productid", productid);
        client.post(context, Url.addtoCollect, params, backcall);
    }

    /**
     * 取消收藏
     */
    public void cancelcollect(String token, String productid, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("productid", productid);
        client.post(context, Url.cancelCollect, params, backcall);
    }

    /**
     * 我的收藏
     */
    public void mycollect(String token, String page, String offset, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("page", page);
        params.put("offset", offset);
        client.post(context, Url.myCollect, params, backcall);
    }

    /**
     * 更新收货地址
     */
    public void dizhi(String token, String name, String address, String phone, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("name", name);
        params.put("address", address);
        params.put("phone", phone);
        client.post(context, Url.dizhi, params, backcall);
    }

    /**
     * 支付宝支付
     */
    public void aliPay(String token, String id, JsonHttpResponseHandler backall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("orderid", id);
        client.post(context, Url.aliPay, params, backall);
    }

    /**
     * 支付宝团队支付
     */
    public void aliPayteam(String id, JsonHttpResponseHandler backall) {
        RequestParams params = new RequestParams();
        params.put("orderid", id);
        client.post(context, Url.aliPayteam, params, backall);
    }

    /**
     * 我的团队
     */
    public void Myteam(String token, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        client.post(context, Url.myTeam, params, backcall);
    }

    /**
     * 团队详情
     */
    public void Teamdetail(String token, String teamid, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("teamid", teamid);
        client.post(context, Url.teamDetail, params, backcall);
    }

    /**
     * 返回团队订单
     */
    public void teamorder(String token, String page, String offset, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("page", page);
        params.put("offset", offset);
        client.post(context, Url.teamOrder, params, backcall);
    }

    /**
     * 返回团队订单详情
     */
    public void teamorderdetail(String token, String orderid, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("orderid", orderid);
        client.post(context, Url.teamorderDetail, params, backcall);
    }

    /**
     * 取消团队订单
     */
    public void cancelteamorder(String token, String orderid, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("orderid", orderid);
        client.post(context, Url.teamorderCancel, params, backcall);
    }

    /**
     * 删除团队订单
     */
    public void deleteteamorder(String token, String orderid, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("orderid", orderid);
        client.post(context, Url.teamorderDelete, params, backcall);
    }

    /**
     * 查询余额
     */
    public void getBalance(String token, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        client.post(context, Url.getBalance, params, backcall);
    }
    /**余额支付*/
//	public void submitpay(String token,String orderid,JsonHttpResponseHandler backcall){
//		RequestParams params = new RequestParams();
//		params.put("token", token);
//		params.put("orderid", orderid);
//		client.post(context, Url.submitpay,params, backcall);
//	}

    /**
     * 联系电话
     */
    public void getPhone(String token, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        client.post(context, Url.getPhone, params, backcall);
    }

    /**
     * 商品详情
     */
    public void getProductdetail(String token, String productid, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("productid", productid);
        client.post(context, Url.getProductdetail, params, backcall);
    }

    /**
     * 商品详情
     */
    public void getAddress(String token, String lot, String lat, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("lot", lot);
        params.put("lat", lat);
        client.post(context, Url.getAddress, params, backcall);
    }

    /**
     * 申请退款
     */
    public void refund(String token, String orderid, String note, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("orderid", orderid);
        params.put("note", note);
        client.post(context, Url.refund, params, backcall);
    }

    /**
     * 我的优惠券
     */
    public void myCoupon(String token, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        client.post(context, Url.myCoupon, params, backcall);
    }

    /**
     * 可用优惠券
     */
    public void getCoupons(String token, String orderid, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("orderid", orderid);
        client.post(context, Url.getCoupons, params, backcall);
    }

    /**
     * 使用优惠券
     */
    public void updateCoupon(String token, String coupondetailid, String orderid, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("coupondetailid", coupondetailid);
        params.put("orderid", orderid);
        client.post(context, Url.updateCoupon, params, backcall);
    }

    /**
     * 返回幻灯片
     */
    public void getPictures(String token, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        client.post(context, Url.getPictures, params, backcall);
    }

    /**
     * 支付失败时返回优惠券
     */
    public void resetCoupon(String token, String coupondetailid, String orderid, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("coupondetailid", coupondetailid);
        params.put("orderid", orderid);
        client.post(context, Url.resetCoupon, params, backcall);
    }

    /**
     * 商品大类
     */
    public void getCategories(String token, int type, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("type", type);
        client.post(context, Url.getCategories, params, backcall);
    }

    /**
     * 商品二级分类
     */
    public void getTwoSort(String token, String catid, String page, String offset, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("catid", catid);
        params.put("page", page);
        params.put("offset", offset);
        client.post(context, Url.getTwoSort, params, backcall);
    }
//	/**搜索商品*/
//	public void searchProduct(String token,String name,String page,String offset,JsonHttpResponseHandler backcall){
//		RequestParams params = new RequestParams();
//		params.put("token", token);
//		params.put("name", name);
//		params.put("page", page);
//		params.put("offset", offset);
//		client.post(context, Url.searchProduct,params, backcall);
//	}

    /**
     * 最新小贴士
     */
    public void getArticle(String token, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        client.post(context, Url.getArticle, params, backcall);
    }

    /**
     * 小贴士列表
     */
    public void getArticles(String token, String page, String offset, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("page", page);
        params.put("offset", offset);
        client.post(context, Url.getArticles, params, backcall);
    }

    /**
     * 小贴士详情
     */
    public void getArticleDetail(String token, String id, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("id", id);
        client.post(context, Url.getArticleDetail, params, backcall);
    }

    /**
     * 返回午餐取消日期
     */
    public void getLunch(String token, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        client.post(context, Url.getLunch, params, backcall);
    }

    /**
     * 首页信息
     */
    public void getHomeInfo(String token, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        client.post(context, Url.getHomeInfo, params, backcall);
    }

    /**
     * 首页消息
     */
    public void getHomeMessage(String token, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        client.post(context, Url.getHomeMessage, params, backcall);
    }

    /**
     * 保存午餐取消就餐
     */
    public void saveLunch(String token, String date, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("date", date);
        client.post(context, Url.saveLunch, params, backcall);
    }

    /**
     * 删除午餐取消就餐
     */
    public void deleteLunch(String token, String date, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("date", date);
        client.post(context, Url.deleteLunch, params, backcall);
    }

    /**
     * 删除午餐取消就餐
     */
    public void saveAdvise(String token, String content, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("content", content);
        client.post(context, Url.saveAdvise, params, backcall);
    }

    /**
     * 更新个人信息
     */
    public void updateInfo(String token, String height, String weight, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("height", height);
        params.put("weight", weight);
        client.post(context, Url.updateInfo, params, backcall);
    }

    /**
     * 小贴士列表
     */
    public void getMessage(String token, String page, String offset, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("page", page);
        params.put("offset", offset);
        client.post(context, Url.getMessage, params, backcall);
    }

    /**
     * 获取二维码
     */
    public void getCode(String token, String orderid, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("orderid", orderid);
        client.post(context, Url.getCode, params, backcall);
    }

    /**
     * 获取二维码
     */
    public void getErweima(String token, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        client.post(context, Url.getErweima, params, backcall);
    }

    /**
     * 扫码
     */
    public void getConsume(String token, String balance, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("balance", balance);
        client.post(context, Url.getConsume, params, backcall);
    }

    /**
     * 消费记录
     */
    public void consumeRecords(String token, String page, String offset, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("page", page);
        params.put("offset", offset);
        client.post(context, Url.consumeRecords, params, backcall);
    }

    /**
     * 充值、退款记录
     */
    public void balanceRecords(String token, String page, String offset, String type, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("page", page);
        params.put("offset", offset);
        params.put("type", type);
        client.post(context, Url.balanceRecords, params, backcall);
    }

    /**
     * 返回版本号
     */
    public void getVersion(String token, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        client.post(context, Url.getVersion, params, backcall);
    }

    /**
     * 搜索
     */
    public void searchProduct(String token, String name, String page, String offset, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("name", name);
        params.put("page", page);
        params.put("offset", offset);
        client.post(context, Url.searchProduct, params, backcall);
    }

    /**
     * 头像上传
     */
    public void updateLogo(String token, String pic, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("pic", pic);
        client.post(context, Url.updateLogo, params, backcall);
    }

    /**
     * 获取修改密码验证码
     */
    public void sendCode(String token, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        client.post(context, Url.sendCode, params, backcall);
    }

    /**
     * 修改密码
     */
    public void updatepassword(String token, String password, String code, JsonHttpResponseHandler backcall) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("password", password);
        params.put("code", code);
        client.post(context, Url.updatepassword, params, backcall);
    }
}
